namespace Csharp01._1014;

public class student
{
    public class Student
    {
        // 学生的属性
        private string name;
        private int age;
        private string studentId;
        private double gpa;
        
        // 构造函数
        public Student()
        {
            name = "";
            age = 0;
            studentId = "";
            gpa = 0.0;
        }
        
        // 带参数的构造函数
        public Student(string name, int age, string studentId, double gpa)
        {
            this.name = name;
            this.age = age;
            this.studentId = studentId;
            this.gpa = gpa;
        }
        
        // Name属性的getter和setter
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        
        // Age属性的getter和setter
        public int Age
        {
            get { return age; }
            set 
            { 
                if (value > 0 && value < 150)
                    age = value; 
                else
                    Console.WriteLine("年龄输入无效！");
            }
        }
        
        // StudentId属性的getter和setter
        public string StudentId
        {
            get { return studentId; }
            set { studentId = value; }
        }
        
       
        public double Gpa
        {
            get { return gpa; }
            set 
            { 
                if (value >= 0.0 && value <= 4.0)
                    gpa = value; 
                else
                    Console.WriteLine("GPA应在0.0到4.0之间！");
            }
        }
        
     
        public void DisplayInfo()
        {
            Console.WriteLine($"学生姓名: {name}");
            Console.WriteLine($"学生年龄: {age}");
            Console.WriteLine($"学生学号: {studentId}");
            Console.WriteLine($"学生GPA: {gpa:F2}");
        }
        
     
    }
}